#!/usr/bin/env bash
#
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# This script runs the necessary Flutter commands to build the Flutter assets
# than need to be packaged in an embedding application.
# It should be called with one argument, which is the directory of the
# Flutter application to build.

readonly base_dir="$(dirname "$0")"
readonly flutter_dir="$("$base_dir/flutter_location")"
readonly flutter_binary="$flutter_dir/bin/flutter"

# To use a custom Flutter engine, uncomment the following variables, and set
# engine_src_path to the path on your machine to your Flutter engine tree's
# src/ directory (and build_type if your engine build is not debug).
#readonly engine_src_path="/path/to/engine/src"
#readonly build_type=host_debug_unopt
#readonly extra_flags=(--local-engine-src-path $engine_src_path --local-engine=$build_type)

cd $1
echo Running "$flutter_binary" ${extra_flags[*]} build bundle
exec "$flutter_binary" ${extra_flags[*]} build bundle
